package capaPresentacion;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Iterator;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;

import capaDatos.Point;

public class Engine extends JPanel implements MouseListener, MouseMotionListener {
	private static final long serialVersionUID = 1L;
	private CtrlMapa s;
	
	public Engine() {		
		setDoubleBuffered(true);
		addMouseListener(this);	
		addMouseMotionListener(this);
		s = CtrlMapa.getInstancia();
		BufferedImage myPicture = null;
		try {
			URL a = this.getClass().getClassLoader().getResource("/GeoChatServidorPrincipal/img/mapamundi.gif");
			System.out.println("Engine.Engine: "+a);
			myPicture = ImageIO.read(new File("C:/Temp/GeoChatServidorPrincipal/img/mapamundi.gif"));
		} catch (IOException e) {
			e.printStackTrace();
		}
		JLabel picLabel = new JLabel(new ImageIcon( myPicture ));
		picLabel.setSize(360, 170);
		add( picLabel );
	}
	
	public void paint(Graphics g) {
		super.paint(g);
		Iterator<Integer> servs = s.getServidores();
		
		
		
		while (servs.hasNext()) {
			Integer integer = (Integer) servs.next();
			Point[] ps = s.getLocationServidor(integer);

			g.setColor(Color.BLACK);
			g.drawRect((int)ps[0].x,(int) ps[0].y,(int) ps[1].x,(int) ps[1].y); 
		}		 		
	}


	@Override
	public void mouseDragged(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseMoved(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseClicked(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseEntered(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mousePressed(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseReleased(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	
}
